package day12_coll.demo08_comparable;
import java.util.Comparator;
import java.util.TreeSet;
public class Test1 {
    public static void main(String[] args) {
        //比较总分，相同（每课都相同，如果不相同，按照数学成绩从大到小降序)
        //赵六，王五，张三，李四
        //o1表示插入的数据
        //o2表示已存在的数据
        Student ls = new Student("李四", 50, 80);
        Student ww = new Student("王五", 55, 90);
        Student zl = new Student("赵六", 80, 90);
        Student zs = new Student("张三", 80, 50);
        TreeSet<Student> students = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int sum=(o2.getSum1()+o2.getSum2())-(o1.getSum1()+o1.getSum2());
//                if (sum==0){
//                    if (o2.getSum1()==o1.getSum1()){
//                        return sum;
//                    }else{
//                        int i=o2.getSum1()-o1.getSum1();
//                        return i;
//                    }
//                }else{
//                    return sum;
//                }
                int i=(sum==0&&!(o2.getSum1()==o1.getSum1()))?o2.getSum1()-o1.getSum1():sum;
                return i;//三元来写
            }
        });
        students.add(ls);
        students.add(ww);
        students.add(zl);
        students.add(zs);
        for (Student student : students) {
            System.out.println(student.getName()+"——"+"数学成绩"+":"+student.getSum1()+"语文成绩"+":"+student.getSum2());
        }
    }
}

